package com.ruoyi.fileTemplate.controller;
import java.awt.*;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.file.FileUtils;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fileTemplate.domain.Templatefile;
import com.ruoyi.fileTemplate.service.ITemplatefileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件信息Controller
 * 
 * @author wad
 * @date 2022-04-13
 */
@RestController
@RequestMapping("/fileTemplate/templateFile")
public class TemplatefileController extends BaseController
{
    @Autowired
    private ITemplatefileService templatefileService;

    /**
     * 查询文件信息列表
     */
    @PreAuthorize("@ss.hasPermi('fileTemplate:templateFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(Templatefile templatefile)
    {
        startPage();
        List<Templatefile> list = templatefileService.selectTemplatefileList(templatefile);
        return getDataTable(list);
    }


    /**
     * 导出文件信息列表
     */
    @PreAuthorize("@ss.hasPermi('fileTemplate:templateFile:export')")
    @Log(title = "文件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Templatefile templatefile)
    {
        List<Templatefile> list = templatefileService.selectTemplatefileList(templatefile);
        ExcelUtil<Templatefile> util = new ExcelUtil<Templatefile>(Templatefile.class);
        util.exportExcel(response, list, "文件信息数据");
    }

    /**
     * 获取文件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('fileTemplate:templateFile:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return AjaxResult.success(templatefileService.selectTemplatefileByFileId(fileId));
    }

    /**
     * 新增文件信息
     */
    @PreAuthorize("@ss.hasPermi('fileTemplate:templateFile:add')")
    @Log(title = "文件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Templatefile templatefile)
    {
        return toAjax(templatefileService.insertTemplatefile(templatefile));
    }

    /**
     * 修改文件信息
     */
    @PreAuthorize("@ss.hasPermi('fileTemplate:templateFile:edit')")
    @Log(title = "文件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Templatefile templatefile)
    {
        return toAjax(templatefileService.updateTemplatefile(templatefile));
    }

    /**
     * 删除文件信息
     */
    @PreAuthorize("@ss.hasPermi('fileTemplate:templateFile:remove')")
    @Log(title = "文件信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(templatefileService.deleteTemplatefileByFileIds(fileIds));
    }
}
